
package hk.ces.oxfam.patch.xml.factory;

import hk.ces.oxfam.patch.xml.DataXML;
import hk.ces.oxfam.patch.xml.SimpleXML;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

/**
 *
 * @author ReutyCheng
 */
public class DataXMLFactory extends AbstractXMLFactory<DataXML>
{
  private static final String NODE_DATA_RESULTS = "DataResult";

  protected DataXMLFactory(String fileName)
  {
    super(fileName);
  }

  protected DataXMLFactory(String folder, String fileName)
  {
    super(folder, fileName);
  }
  
  @Override
  protected Document getDocument()
  {
    Document document = DocumentHelper.createDocument();
    Element dataResultsElement = this.createDataResults(document);
    SimpleXMLFactory factory = new SimpleXMLFactory();

    for (DataXML result : this.getXMLItems())
    {
      if (result instanceof SimpleXML)
      {
        SimpleXML simpleXML = (SimpleXML) result;
        factory.setSimpleXML(simpleXML);

        factory.createHeaders(dataResultsElement);
        factory.createBodyItems(dataResultsElement);
      }
    }

    return document;
  }

  @Override
  protected String getXslPath()
  {
    return null;
  }

  private Element createDataResults(Document document)
  {
    return document.addElement(NODE_DATA_RESULTS);
  }
}
